import { BoxGeometry, Mesh, MeshStandardMaterial, MathUtils, TextureLoader } from "../three_lib/three.module.min.js";

function createMaterial() {
    const textureLoader = new TextureLoader();
    const texture = textureLoader.load(
        'http://172.20.209.65:3333/api/getimg',
    );

    /* 材质  材质定义了网格表面的外观 */
    const material = new MeshStandardMaterial();
    material.map = texture;
    return material;
}

function createCube() {
    /* 几何体  盒子的长度、宽度和深度 单位是米 */
    const geometry = new BoxGeometry(2, 2, 2);
    /* 材质  材质定义了网格表面的外观 */
    const meterial = createMaterial();
    /* 网格 */
    const cube = new Mesh(geometry, meterial);
    /* 旋转 */
    cube.rotation.set(-0.5, -0.1, 0.8);

    const radiansPerSecond = MathUtils.degToRad(30);

    // this method will be called once per frame
    cube.tick = (delta) => {
        // increase the cube's rotation each frame
        cube.rotation.z += radiansPerSecond * delta;
        cube.rotation.x += radiansPerSecond * delta;
        cube.rotation.y += radiansPerSecond * delta;
    };


    return cube;
}

export { createCube };

/* TRS: translation, rotation, scale   平移，旋转，缩放 */